<template>
	<view class="view">
		<uni-grid :column="2">
			<uni-grid-item v-for="(item,index) in search" :key="index">
			<view @click="caketo(index)" style="font-size: 12px;  display: flex;flex-direction: column; justify-content: center;align-items: center;">
					<image :src="item.cakeImage" mode="widthFix" style="width: 70%; "></image>
					<text>{{item.cakeName}}</text>
					<text>购买数:{{item.cakeNumber}}</text>
					<!-- <text>购买数:{{item.}}</text> -->
					<uni-rate :max="5" :value="item.cakeScore" />
					<text style="font-weight: bold;color: #800;">${{item.cakeMoney}}</text>
			</view>
				</uni-grid-item>
			
			
		</uni-grid>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				search:[]
			}
		},
		methods: {
			caketo(index){
				uni.navigateTo({
					url: '/pages/cake/cake?id='+this.search[index].id,
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			getsearch(cakeName){
				uni.request({
					url: this.api.search,
					method: 'POST',
					data: {
						cakeName:cakeName
					},
					success: res => {
						if(res.data.code==200){
								this.search=res.data.obj
								for (var i = 0; i < this.search.length; i++) {
									this.search[i].cakeImage="http://127.0.0.1:8989/"+this.search[i].cakeImage															
							}
						}
						else{
							this.search=res.data.obj
								for (var i = 0; i < this.search.length; i++) {
									this.search[i].cakeImage="http://127.0.0.1:8989/"+this.search[i].cakeImage															
							}
						}
					},
					fail: () => {},
					complete: () => {}
				});
			},
		},
		onLoad(open) {
			uni.setNavigationBarTitle({
				title:open.name
			})
			this.getsearch(open.name)
		}
	}
</script>

<style>
	page,.view{
		width: 100%;
		height: 100%;
	}
</style>
